package com.tjh.gulimall.auth.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.session.web.http.CookieSerializer;
import org.springframework.session.web.http.DefaultCookieSerializer;

/**
 * day100
 * Create by koala on 2021-05-13
 */
@Configuration
public class GulimallSessionConfig {

    @Bean
    public CookieSerializer cookieSerializer(){
        DefaultCookieSerializer cookieSerializer = new DefaultCookieSerializer();
        //下面设置的信息可在浏览器中--》f12 --》Application --》 Cookies 中找到
        cookieSerializer.setDomainName("gulimall.com");//解决cookie的不同子域问题，提升cookie的Domain为父域名
        cookieSerializer.setCookieName("GULISESSION");
        return cookieSerializer;
    }

    //解决redis的序列化问题
    @Bean
    public RedisSerializer<Object> springSessionDefaultRedisSerializer(){
        return new GenericJackson2JsonRedisSerializer();
    }
}